// Decompiled by Jad v1.5.8g. Copyright 2001 Pavel Kouznetsov.
// Jad home page: http://www.kpdus.com/jad.html
// Decompiler options: packimports(3) 
// Source File Name:   SimpleCommand.java

package org.quickserver.net.qsadmin.gui;

import org.quickserver.util.MyString;

public class SimpleCommand
{

    public SimpleCommand()
    {
        target = "server";
        targetNeeded = "yes";
        multiLineResponse = "no";
        version = "1.3";
    }

    public String getSimpleCommand()
    {
        if(targetNeeded.equals("yes"))
            return (new StringBuilder(String.valueOf(command))).append(" ").append(target).toString();
        else
            return command;
    }

    public String getName()
    {
        return name;
    }

    public void setName(String name)
    {
        this.name = name;
    }

    public String getTarget()
    {
        return target;
    }

    public void setTarget(String target)
    {
        this.target = target;
    }

    public String getCommand()
    {
        return command;
    }

    public void setCommand(String command)
    {
        this.command = command;
    }

    public String getDesc()
    {
        return desc;
    }

    public void setDesc(String desc)
    {
        this.desc = desc;
    }

    public String getTargetNeeded()
    {
        return targetNeeded;
    }

    public void setTargetNeeded(String targetNeeded)
    {
        this.targetNeeded = targetNeeded.toLowerCase();
    }

    public String getMultiLineResponse()
    {
        return multiLineResponse;
    }

    public void setMultiLineResponse(String multiLineResponse)
    {
        this.multiLineResponse = multiLineResponse.toLowerCase();
    }

    public String getVersion()
    {
        return version;
    }

    public float getVersionNo()
    {
        return getVersionNo(version);
    }

    public void setVersion(String version)
    {
        if(version != null && !version.equals(""))
            this.version = version.toLowerCase();
    }

    public String toXML()
    {
        StringBuilder sb = new StringBuilder();
        sb.append("<simple-command>\n");
        sb.append("\t<name>").append(name).append("</name>\n");
        sb.append("\t<command>").append(command).append("</command>\n");
        if(multiLineResponse != null && multiLineResponse.equals("yes"))
            sb.append("\t<multi-line-response>yes</multi-line-response>\n");
        else
            sb.append("\t<multi-line-response>no</multi-line-response>\n");
        if(desc != null)
            sb.append("\t<desc>").append(desc).append("</desc>\n");
        sb.append("\t<version>").append(version).append("</version>\n");
        if(targetNeeded != null && targetNeeded.equals("yes"))
            sb.append("\t<target-needed>yes</target-needed>\n");
        else
            sb.append("\t<target-needed>no</target-needed>\n");
        sb.append("</simple-command>\n");
        return sb.toString();
    }

    private static final float getVersionNo(String ver)
    {
        float version = 0.0F;
        int i = ver.indexOf(" ");
        if(i == -1)
            i = ver.length();
        ver = ver.substring(0, i);
        i = ver.indexOf(".");
        if(i != -1)
        {
            int j = ver.indexOf(".", i);
            if(j != -1)
                ver = (new StringBuilder(String.valueOf(ver.substring(0, i)))).append(".").append(MyString.replaceAll(ver.substring(i + 1), ".", "")).toString();
        }
        try
        {
            version = Float.parseFloat(ver);
        }
        catch(NumberFormatException e)
        {
            throw new RuntimeException("Corrupt QuickServer");
        }
        return version;
    }

    private String name;
    private String target;
    private String command;
    private String desc;
    private String targetNeeded;
    private String multiLineResponse;
    private String version;
}
